package com.kitty.game.fight.bean;

import com.kitty.game.guard.model.Guard;
import com.kitty.game.config.GuardSet;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.enter.FiedValue;
import com.kitty.game.fight.message.vo.FightMember;
import com.kitty.game.fight.util.FightRateUtil;
import com.kitty.game.fight.service.CountService;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

public class GuardFightObject extends FightObject {

    @Getter
    private Guard guardObject;

    public GuardFightObject(Guard guard, GuardSet guardSet, int pos, boolean isA) {
        setName(guard.getName());
        setLevel(guard.getLevel());
        setId(guard.getId());
        setPolar(guardSet.getMenpai());
        setIcon(guardSet.getIcon());
        setType(3);
        setASide(isA);
        this.guardObject = guard;
        setPos(pos);

        CountService countService = SpringUtils.getHurtService();
        int phyPower = new Double(countService.countPhyPower(guard.getEarth(), guard.getStr()) * 2).intValue();
        int magPower = new Double(countService.countMagPower(guard.getMetal(), guard.getWiz()) * 3).intValue();
        int defense = new Double(countService.countDefense(guard.getWater(), guard.getCon()) * 3).intValue();
        int speed = new Double(countService.countSpeed(guard.getFire(), guard.getDex()) * 1.5).intValue();
        int life = new Double(countService.countLife(guard.getLevel(), guard.getWood(), guard.getCon()) * 1.7).intValue();
        setMaxLife(life);
        setCurrLife(life);
        setDefense(defense);
        setSpeed((short) speed);
        setMagPower(magPower);
        setPhyPower(phyPower);
    }

    @Override
    public FightMember asFightMember() {
        FightMember fightMember = new FightMember();
        fightMember.setId(getId());
        Guard guard = getGuardObject();
        fightMember.setPosition((short) getPos());
        fightMember.setColor(guard.getColor()); // 2紫色
        fightMember.setIcon((short) getIcon());
        fightMember.setList(asFieldValues());

        return fightMember;
    }

    @Override
    public List<FiedValue> asFieldValues() {
        ArrayList<FiedValue> fiedValues = new ArrayList<>();
        fiedValues.add(new FiedValue(1, getName()));
        fiedValues.add(new FiedValue(40, getIcon()));
        fiedValues.add(new FiedValue(41, 32));
        fiedValues.add(new FiedValue(204, getHostId()));
        fiedValues.add(new FiedValue(341, (byte) 0));
        fiedValues.add(new FiedValue(340, (byte) 0));
        fiedValues.add(new FiedValue(6, getCurrLife()));
        fiedValues.add(new FiedValue(7, getMaxLife()));
        return fiedValues;
    }

    @Override
    public int getMagHurt(FightObject target, boolean isPenetrate) {
        return this.getMagPower() + FightRateUtil.getRandHurt(this.getMagPower()) - target.getDefense() - target.getExtraDefense();
    }

    @Override
    public int getPhyHurt(FightObject target, boolean isPenetrate) {
        return this.getPhyPower() + FightRateUtil.getRandHurt(this.getPhyPower()) - target.getDefense() - target.getExtraDefense();
    }

    @Override
    public String toString() {
        return "GuardFightObject{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
